package com.tjshop.android.view;

import java.util.ArrayList;
import java.util.List;

import com.tjshop.android.R;
import com.tjshop.android.model.CouponHomeData;
import com.tjshop.android.model.keyPair;
import com.tjshop.android.view.CategoryPopWindow.MyAdapter;
import com.tjshop.android.view.CategoryPopWindow.OnClickListener;
import com.tjshop.android.view.CategoryPopWindow.ViewHolder;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.PaintDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class WhetherUseCouponPopWindow extends PopupWindow {
	private Context mContext;
	private OnClickListener clickListener;
	private View contentView;

	public WhetherUseCouponPopWindow(Context context,
			final OnClickListener listener) {
		this.mContext = context;
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		contentView = inflater.inflate(
				R.layout.popupwindow_for_whetherusercoupon, null);
		// 设置SelectPicPopupWindow的View
		this.setContentView(contentView);
		setFocusable(true);
		WindowManager wm = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		int width = wm.getDefaultDisplay().getWidth();
		int height = wm.getDefaultDisplay().getHeight();
		this.setWidth(width);
		this.setHeight(height / 4);
		// this.setFocusable(true);
		this.clickListener = listener;
		this.setOutsideTouchable(true);
		this.setBackgroundDrawable(new PaintDrawable());
		this.update();

		Button user = (Button) contentView.findViewById(R.id.use_coupon);
		Button close = (Button) contentView.findViewById(R.id.close);

		user.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				if (clickListener != null) {
					dismiss();
					clickListener.onClickUse();
				}
			}
		});
		close.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				dismiss();
			}
		});
		// this.setAnimationStyle(R.style.AnimationFade);

	}

	public static interface OnClickListener {
		public void onClickUse();
	}

	/**
	 * 显示popupWindow
	 * 
	 * @param parent
	 */
	@SuppressLint("NewApi")
	public void showPopupWindow(View parent) {
		if (!this.isShowing()) {
			WindowManager wm = (WindowManager) mContext
					.getSystemService(Context.WINDOW_SERVICE);
			int height = wm.getDefaultDisplay().getHeight();
			this.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
		} else {
			this.dismiss();
		}
	}
}
